package com.yupi.mianshiya.model.vo;

import com.fasterxml.jackson.annotation.JsonFormat;

import com.yupi.mianshiya.model.entity.Comments;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.util.Date;

@Data
public class CommentsVO {
    private Long id;

    /**
     * 关联文章ID
     */
    private Long articleId;

    /**
     * 评论用户ID
     */
    private Long userId;

    /**
     * 评论用户昵称
     */
    private String userName;

    /**
     * 评论用户头像
     */
    private String userAvatar;
    /**
     * 父评论ID(用于回复)
     */
    private Long parentId;

    /**
     * 回复用户ID
     */
    private Long replyUserId;

    /**
     * 回复用户昵称
     */
    private String replyUserName;

    /**
     * 评论内容
     */
    private String content;

    /**
     * 点赞数
     */
    private Integer likeCount;

    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createTime;

    //vo转换成对象的方法
    public static Comments voToObj(CommentsVO commentsVO ) {
        if (commentsVO == null) {
            return null;
        }
        Comments comments = new Comments();

        BeanUtils.copyProperties(commentsVO, comments);
        return comments;
    }

    //对象转换成vo的方法
    public static CommentsVO objToVo(Comments comments) {
        if (comments == null) {
            return null;
        }
        CommentsVO commentsVO = new CommentsVO();

        BeanUtils.copyProperties(comments, commentsVO);
        return commentsVO;
    }
}
